import { defineStore } from "pinia";
import { UserState } from "@/stores/interface";
import piniaPersistConfig from "@/stores/helper/persist";

export const useUserStore = defineStore({
  // id: "geeker-user",
  id: "geeker-user",
  state: (): UserState => ({
    id: 0,
    token: "",
    // userInfo: { name: "Geeker" }
    // userInfo: { name: "", avatar: "" }
    name: "",
    avatar: ""
  }),
  getters: {},
  actions: {
    // Set Token
    setToken(token: string) {
      this.token = token;
    },
    setName(name: string) {
      this.name = name;
    },
    setavatar(avatar: string) {
      this.avatar = avatar;
    },
    setUserId(id: number) {
      this.id = id;
    },
    resetUser() {
      this.id = 0;
      this.token = "";
      this.name = "";
      this.avatar = "";
    },
    printState() {
      console.log("当前用户状态:", {
        token: this.token,
        name: this.name,
        avatar: this.avatar,
        id: this.id
      });
    }
  },
  persist: piniaPersistConfig("geeker-user")
});
